package quartz1;

import java.util.Date;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.DateBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzDemo2 {
	
	
	
	public void quartzRun() throws Exception{
		
		SchedulerFactory sfFactory = new StdSchedulerFactory();
		
		Scheduler sche=sfFactory.getScheduler();
		
		Date runtime = DateBuilder.nextGivenSecondDate(null, 10);
		
		JobDetail job=JobBuilder.newJob(ColorJob.class).
				withIdentity("colorjob", "g2").build();
		SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder
				.newTrigger()
				.startAt(runtime)
				.withIdentity("trigger1", "group1")
				.withSchedule(
						SimpleScheduleBuilder.simpleSchedule()
								.withIntervalInSeconds(10).withRepeatCount(4))
				.build();
		
		job.getJobDataMap().put(ColorJob.FAVOURATE_COLOR, "Red");
		job.getJobDataMap().put(ColorJob.EXECUTION_COUNT, 1);
		
		sche.scheduleJob(job, trigger);
		
		
		
		sche.start();
		
	}
	public static void main(String[] args) {
		QuartzDemo2 demo=new QuartzDemo2();
		
		try {
			
			demo.quartzRun();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}
